package com.coolingme.demo.controller;

import com.coolingme.demo.service.HelloService;
import com.coolingme.springframework.annotation.MeAutowired;
import com.coolingme.springframework.annotation.MeController;
import com.coolingme.springframework.annotation.MeRequestMapping;
import com.coolingme.springframework.annotation.MeRequestParam;
import com.coolingme.springframework.webmvc.servlet.MeModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试MVC视图
 *
 * @author wangyue
 * @date 2024/09/04 14:01
 */
@MeController
@MeRequestMapping("/web")
public class WebController {

    @MeAutowired
    private HelloService helloService;

    /**
     * 测试index页面
     */
    @MeRequestMapping("/index.html")
    public MeModelAndView index(@MeRequestParam("name") String name) {
        String result = this.helloService.query(name);
        Map<String, Object> model = new HashMap<>();
        model.put("name", name);
        model.put("data", result);
        model.put("token", "123456");
        return new MeModelAndView("index.html", model);
    }


    /**
     * 测试500页面
     */
    @MeRequestMapping("/error.html")
    public MeModelAndView error() {
        String a = null;
        System.out.println(a.toString());
        return null;
    }

}
